/**
 * 
 */
package com.lanswon.service;

import java.beans.PropertyDescriptor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.xml.datatype.DatatypeFactory;
import javax.xml.datatype.XMLGregorianCalendar;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.lanswon.common.enums.MessageType;
import com.lanswon.common.util.StringUtil;
import com.lanswon.dao.UserMapper;
import com.lanswon.entity.UserVO;
import com.lanswon.qzsmk.service.commonservice.BranchInternetVo;
import com.lanswon.qzsmk.service.commonservice.CardPhysicsType;
import com.lanswon.qzsmk.service.commonservice.CardProdunctDefinition;
import com.lanswon.qzsmk.service.commonservice.Certificate;
import com.lanswon.qzsmk.service.commonservice.DwzPage;
import com.lanswon.qzsmk.service.commonservice.LossCardInfo;
import com.lanswon.qzsmk.service.commonservice.Personal;
import com.lanswon.qzsmk.service.commonservice.ResultObject;
import com.lanswon.qzsmk.service.commonservice.ResultStatus;
import com.lanswon.qzsmk.service.commonservice.ResultVo;
import com.lanswon.qzsmk.service.commonservice.StreetNetVo;
import com.lanswon.qzsmk.service.commonservice.SupplementCardInfo;
import com.lanswon.qzsmk.service.commonservice.VoucherVo;
import com.lanswon.qzsmk.service.commonservice.impl.DockingInternetService;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

/**
 * 
 * @ClassName: AppService.java
 * @Description: 该类的功能描述
 *
 * @version: v1.0.0
 * @author: zm
 * @date: 2018年5月15日 下午5:35:01
 *
 */
@Service
public class CoreService {

	@Autowired
	private DockingInternetService dockingInternetService;

	@Autowired
	private UserService userService;

	@Autowired
	private UserMapper userMapper;

	public JSONObject queryBranch(String streetId, String orgProperty) {
		JSONObject jsonObject = new JSONObject();
		String serverType = "";
		ResultVo vo = dockingInternetService.queryBranchInternet(streetId, orgProperty, serverType);
		// 核心接口校验
		if (vo.getResultStatus().getCode() != 200) {
			jsonObject.put("code", 1);
			jsonObject.put("message", vo.getResultStatus().getMessage());
			return jsonObject;
		}
		ResultObject obj = (ResultObject) vo.getServiceObject();
		List<Object> list = obj.getItems();
		if (list != null && list.size() > 0) {
			JSONArray jsonArray = new JSONArray();
			// 处理数据
			for (Object object : list) {
				
				jsonArray.add(putMessage(object));
			}
			jsonObject.put("code", 0);
			jsonObject.put("message", MessageType.MT007);
			jsonObject.put("data", jsonArray);
		} else {
			jsonObject.put("code", 1);
			jsonObject.put("message", MessageType.MT_CX_4);
		}

		return jsonObject;
	}

	public JSONObject testWS() {
		String ws = dockingInternetService.testWS();
		System.out.println(ws);
		return null;
	}
	
	/**
	 * @param currentPage
	 * @param numPerPage
	 * @param startLine
	 * @param userId
	 * @return
	 */
	public JSONObject queryLossCard(int startLine, int numPerPage, int currentPage, Long userId) {
		JSONObject jsonObject = new JSONObject();
		try {
			// 业务校验，绑定信息
			UserVO vo = userMapper.selectByPrimaryKey(userId);
			if (StringUtil.isEmpty(vo.getCustomerNo())) {
				jsonObject.put("code", 40);
				jsonObject.put("message", MessageType.MT005);
				return jsonObject;
			}
			// 核心接口调用
			LossCardInfo lci = new LossCardInfo();
			lci.setPaperType(vo.getPapertype());
			lci.setPaperNo(vo.getPaperno());
			lci.setStartLine(startLine);
			lci.setCurrentPage(currentPage);
			lci.setNumPerPage(numPerPage);
			ResultVo resultVo = dockingInternetService.queryLossCard(lci);
			// 核心接口校验
			if (resultVo.getResultStatus().getCode() != 200) {
				jsonObject.put("code", 1);
				jsonObject.put("message", resultVo.getResultStatus().getMessage());
				return jsonObject;
			}
			List lasslist = ((DwzPage) resultVo.getServiceObject()).getList();

			if (lasslist != null && lasslist.size() > 0) {
				// 处理数据
				JSONArray jsonArray = new JSONArray();
				for (Object obj : lasslist) {
					jsonArray.add(putMessage((LossCardInfo) obj));
				}
				jsonObject.put("code", 0);
				jsonObject.put("message", MessageType.MT007);
				jsonObject.put("data", jsonArray);
			} else {
				jsonObject.put("code", 1);
				jsonObject.put("message", MessageType.MT_CX_5);
			}
		} catch (Exception e) {
			jsonObject.put("code", 1);
			jsonObject.put("message", MessageType.MT008);
			e.printStackTrace();
		}
		return jsonObject;
	}

	/**
	 * @param citizenCardNo
	 * @param cardPName
	 * @param paperTypeName
	 * @param paperNo
	 * @return
	 */
	public JSONObject commitLossCardInfo(String citizenCardNo, String cardPName, String cardStatus, Long userId) {
		JSONObject jsonObject = new JSONObject();
		try {
			// 业务校验，绑定信息
			UserVO vo = userMapper.selectByPrimaryKey(Long.valueOf(userId));
			if (StringUtil.isEmpty(vo.getCustomerNo())) {
				jsonObject.put("code", 40);
				jsonObject.put("message", MessageType.MT005);
				return jsonObject;
			}
			// 核心接口调用
			ResultVo qAC = dockingInternetService.queryAllCertificates();
			if (qAC.getResultStatus().getCode() != 200) {
				jsonObject.put("code", 1);
				jsonObject.put("message", qAC.getResultStatus().getMessage());
				return jsonObject;
			}
			LossCardInfo lci = new LossCardInfo();
			ResultObject obj = (ResultObject) qAC.getServiceObject();
			List<Object> certificates = obj.getItems();
			for (Object object : certificates) {
				Certificate certificate = (Certificate) object;
				if (vo.getPapertype().equals(certificate.getCertificateType())) {
					lci.setPaperTypeName(certificate.getCertificatesName());
					break;
				}
			}

			lci.setCitizenCardNo(citizenCardNo);
			lci.setCardPName(cardPName);
			lci.setPaperNo(vo.getPaperno());
			lci.setCustomerName(vo.getRealName());
			lci.setCardStatus(cardStatus);
			ResultVo resultVo = dockingInternetService.commitLossCardInfo(lci);
			// 核心接口校验
			if (resultVo.getResultStatus().getCode() != 200) {
				jsonObject.put("code", 1);
				jsonObject.put("message", resultVo.getResultStatus().getMessage());
				return jsonObject;
			}
			VoucherVo voucherVo = (VoucherVo) resultVo.getServiceObject();
			// 处理数据
			jsonObject.put("code", 0);
			jsonObject.put("message", MessageType.MT007);
			jsonObject.put("data", putMessage(voucherVo));
		} catch (Exception e) {
			e.printStackTrace();
			jsonObject.put("code", 1);
			jsonObject.put("message", MessageType.MT008);
		}
		return jsonObject;
	}

	/**
	 * @param paperNo
	 * @param paperType
	 * @param startLine
	 * @param numPerPage
	 * @param currentPage
	 * @return
	 */
	public JSONObject querySupplementCard(int startLine, int numPerPage, int currentPage, Long userId) {
		JSONObject jsonObject = new JSONObject();
		try {
			// 业务校验，绑定信息
			UserVO vo = userMapper.selectByPrimaryKey(userId);
			if (StringUtil.isEmpty(vo.getCustomerNo())) {
				jsonObject.put("code", 40);
				jsonObject.put("message", MessageType.MT005);
				return jsonObject;
			}
			// 核心接口调用
			SupplementCardInfo sci = new SupplementCardInfo();
			sci.setPaperType(vo.getPapertype());
			sci.setPaperNo(vo.getPaperno());
			sci.setStartLine(startLine);
			sci.setNumPerPage(numPerPage);
			sci.setCurrentPage(currentPage);
			ResultVo resultVo = dockingInternetService.querySupplementCard(sci);
			// 核心接口校验
			if (resultVo.getResultStatus().getCode() != 200) {
				jsonObject.put("code", 1);
				jsonObject.put("message", resultVo.getResultStatus().getMessage());
				return jsonObject;
			}
			List lasslist = ((DwzPage) resultVo.getServiceObject()).getList();
			if (lasslist != null && lasslist.size() > 0) {
				// 处理数据
				JSONArray jsonArray = new JSONArray();
				for (Object obj : lasslist) {
					jsonArray.add(putMessage((SupplementCardInfo) obj));
				}
				jsonObject.put("code", 0);
				jsonObject.put("message", MessageType.MT007);
				jsonObject.put("data", jsonArray);
			} else {
				jsonObject.put("code", 1);
				jsonObject.put("message", MessageType.MT_CX_6);
			}
		} catch (Exception e) {
			e.printStackTrace();
			jsonObject.put("code", 1);
			jsonObject.put("message", MessageType.MT008);
		}
		return jsonObject;
	}

	/**
	 * @param paperNo
	 * @param paperType
	 * @param customerName
	 * @param oldCitizenCardNo
	 * @return
	 */
	public JSONObject commitSupplementCardInfo(String oldCitizenCardNo, Long userId) {
		JSONObject jsonObject = new JSONObject();
		try {
			// 业务校验，绑定信息
			UserVO vo = userMapper.selectByPrimaryKey(userId);
			if (StringUtil.isEmpty(vo.getCustomerNo())) {
				jsonObject.put("code", 40);
				jsonObject.put("message", MessageType.MT005);
				return jsonObject;
			}
			// 核心接口调用
			SupplementCardInfo sci = new SupplementCardInfo();
			GregorianCalendar gcDate = new GregorianCalendar();
			GregorianCalendar gcGetDate = new GregorianCalendar();
			// 当前日期
			Calendar cal = Calendar.getInstance();
			Date date = cal.getTime();
			// 日期加3天
			cal.add(Calendar.DAY_OF_YEAR, 3);
			Date getDate = cal.getTime();
			// 设置转换
			gcDate.setTime(date);
			gcGetDate.setTime(getDate);

			XMLGregorianCalendar calendar = null;
			XMLGregorianCalendar calendar2 = null;
			calendar = DatatypeFactory.newInstance().newXMLGregorianCalendar(gcDate);
			calendar2 = DatatypeFactory.newInstance().newXMLGregorianCalendar(gcGetDate);

			// com.lanswon.qzsmk.service.systemmanageservice.ResultVo qAC =
			// paramManageService.getParamManageServicePort()
			// .queryAllCertificates();
			// if (qAC.getResultStatus().getCode() != 200) {
			// jsonObject.put("code", 1);
			// jsonObject.put("message", qAC.getResultStatus().getMessage());
			// return jsonObject;
			// }
			// LossCardInfo lci = new LossCardInfo();
			// List<Object> certificates =
			// ((com.lanswon.qzsmk.service.systemmanageservice.ResultObject) qAC
			// .getServiceObject()).getItems();
			// for (Object object : certificates) {
			// Certificate certificate = (Certificate) object;
			// if (vo.getPapertype().equals(certificate.getCertificateType())) {
			// sci.setPaperType(certificate.getCertificatesName());
			// break;
			// }
			// }
			sci.setPaperType(vo.getPapertype());
			sci.setOldCitizenCardNo(oldCitizenCardNo);
			sci.setSupplementCardDate(calendar);
			sci.setGetCardDate(calendar2);
			sci.setCustomerName(vo.getRealName());
			sci.setPaperNo(vo.getPaperno());
			ResultVo resultVo = dockingInternetService.commitSupplementCardInfo(sci);
			// 核心接口校验
			if (resultVo.getResultStatus().getCode() != 200) {
				jsonObject.put("code", 1);
				jsonObject.put("message", resultVo.getResultStatus().getMessage());
				return jsonObject;
			}
			VoucherVo voucherVo = (VoucherVo) resultVo.getServiceObject();
			// 处理数据
			Map map = putMessage(voucherVo);
			// 特殊处理
			StringUtil.putIntoMap(map, "expectCardDate", voucherVo.getExpectCardDate().toXMLFormat());
			jsonObject.put("code", 0);
			jsonObject.put("message", MessageType.MT007);
			jsonObject.put("data", map);
		} catch (Exception e) {
			e.printStackTrace();
			jsonObject.put("code", 1);
			jsonObject.put("message", MessageType.MT008);
		}
		return jsonObject;
	}

	/**
	 * @param paperType
	 * @param paperNo
	 * @param cardProductCode
	 * @return
	 */
	public JSONObject checkIsCardProductbyPaperNo(String cardProductCode, String paperType, String paperNo,
			Long userId) {
		JSONObject jsonObject = new JSONObject();
		try {
			// 核心接口调用
			ResultVo resultVo = dockingInternetService.checkIsCardProductbyPaperNo(paperType, paperNo, cardProductCode);

			// 核心接口校验
			if (resultVo.getResultStatus().getCode() != 200) {
				jsonObject.put("code", 1);
				jsonObject.put("message", resultVo.getResultStatus().getMessage());
				return jsonObject;
			}
			// 处理数据
			int flag = ((ResultObject) resultVo.getServiceObject()).getVariable();

			if (flag == 3) {
				jsonObject.put("code", 1);
				jsonObject.put("message", MessageType.MT008);
			}
			if (flag == 1 || flag == 2) {
				jsonObject.put("code", 0);
				jsonObject.put("message", MessageType.MT007);
			}
			jsonObject.put("data", flag);
		} catch (Exception e) {
			e.printStackTrace();
			jsonObject.put("code", 1);
			jsonObject.put("message", MessageType.MT008);
		}
		return jsonObject;
	}

	/**
	 * 7个人申请
	 * 
	 * @param p
	 * @param cardProductCode
	 * @param cardPhysicalType
	 * @return
	 */
	public JSONObject singleApplication(Personal p, String cardProductCode, String cardPhysicalType, Long userId)
			throws Exception {
		JSONObject jsonObject = new JSONObject();
		// 民族判断
		/*
		 * com.lanswon.qzsmk.service.systemmanageservice.ResultVo nationResultVo
		 * = paramManageService.getParamManageServicePort().queryNation();
		 * if(nationResultVo.getResultStatus().getCode()==200) {
		 * com.lanswon.qzsmk.service.systemmanageservice.ResultObject nationVO =
		 * (com.lanswon.qzsmk.service.systemmanageservice.ResultObject)
		 * nationResultVo.getServiceObject(); List<Object> items =
		 * nationVO.getItems(); for (Object obj : items) { Nation nation =
		 * (Nation) obj; if(nation.getNumbercode().equals(p.getNationality())) {
		 * p.setNationality(nation.getNumbercode()); break; } } }
		 */

		// 申请
		ResultVo resultVo = dockingInternetService.singleApplication(p, cardProductCode, cardPhysicalType);
		// 核心接口校验
		if (resultVo.getResultStatus().getCode() != 200) {
			jsonObject.put("code", resultVo.getResultStatus().getCode());
			jsonObject.put("message", resultVo.getResultStatus().getMessage());
			return jsonObject;
		}
		// 绑定用户
		//userService.bind(userId, cardPhysicalType, p.getPaperNo());
		// Personal personal = (Personal) resultVo.getServiceObject();
		Map map = putMessage(resultVo.getServiceObject());
		// 特殊处理
		StringUtil.putIntoMap(map, "expectCardDate",
				((VoucherVo) resultVo.getServiceObject()).getExpectCardDate().toXMLFormat());
		jsonObject.put("code", 0);
		jsonObject.put("message", MessageType.MT007);
		jsonObject.put("data", map);
		
		return jsonObject;
	}

	/**
	 * 8基础信息查询（证件类型）
	 */
	public JSONObject queryAllCertificates() {
		JSONObject jsonObject = new JSONObject();
		try {
			ResultVo resultVo = dockingInternetService.queryAllCertificates();
			ResultStatus status = resultVo.getResultStatus();
			if (status.getCode() != 200) {
				jsonObject.put("code", status.getCode());
				jsonObject.put("message", MessageType.MT006);
				return jsonObject;
			}
			ResultObject sObj = (ResultObject) resultVo.getServiceObject();
			jsonObject.put("code", 0);
			jsonObject.put("message", MessageType.MT007);
			jsonObject.put("data", sObj.getItems());

		} catch (Exception e) {
			e.printStackTrace();
			jsonObject.put("code", 1);
			jsonObject.put("message", MessageType.MT008);
		}

		return jsonObject;
	}

	/**
	 * 9基础信息查询（卡产品）
	 */
	public JSONObject queryAllCardProdunctDefinition() {
		JSONObject jsonObject = new JSONObject();
		try {
			ResultVo resultVo = dockingInternetService.queryAllCardProdunctDefinition();
			ResultStatus status = resultVo.getResultStatus();
			if (status.getCode() != 200) {
				jsonObject.put("code", status.getCode());
				jsonObject.put("message", MessageType.MT006);
				return jsonObject;
			}
			ResultObject ro = (ResultObject) resultVo.getServiceObject();
			JSONArray jsonArray = new JSONArray();
			// 处理数据
			for (Object object : ro.getItems()) {
				jsonArray.add(putMessage((CardProdunctDefinition) object));
			}
			jsonObject.put("code", 0);
			jsonObject.put("message", MessageType.MT007);
			jsonObject.put("data", jsonArray);
		} catch (Exception e) {
			e.printStackTrace();
			jsonObject.put("code", 1);
			jsonObject.put("message", MessageType.MT008);
		}

		return jsonObject;
	}

	/**
	 * 10基础信息查询（卡物理类型）
	 */
	public JSONObject queryAllCardPhysicsType() {
		JSONArray jsonArray = new JSONArray();
		JSONObject jsonObject = new JSONObject();
		try {
			ResultVo resultVo = dockingInternetService.queryAllCardPhysicsType();
			ResultStatus status = resultVo.getResultStatus();
			if (status.getCode() != 200) {
				jsonObject.put("code", status.getCode());
				jsonObject.put("message", MessageType.MT006);
				return jsonObject;
			}
			ResultObject ro = (ResultObject) resultVo.getServiceObject();
			List<Object> items = ro.getItems();
			for (Object obj : items) {
				jsonArray.add(putMessage((CardPhysicsType) obj));
			}
			jsonObject.put("code", 0);
			jsonObject.put("message", MessageType.MT007);
			jsonObject.put("data", jsonArray);
		} catch (Exception e) {
			e.printStackTrace();
			jsonObject.put("code", 1);
			jsonObject.put("message", MessageType.MT008);
		}

		return jsonObject;
	}

	/**
	 * 11基础信息查询(个人信息)
	 */
	public JSONObject queryPersonalByPaperNoAndPaperType(String paperType, String paperNo) {
		JSONObject jsonObject = new JSONObject();
		try {
			ResultVo resultVo = dockingInternetService.queryPersonalByPaperNoAndPaperType(paperType, paperNo);
			ResultStatus status = resultVo.getResultStatus();
			if (status.getCode() != 200) {
				jsonObject.put("code", status.getCode());
				jsonObject.put("message", status.getCode() == 28 ? "该证件未办理市民卡" : status.getMessage());
				return jsonObject;
			}
			Map map = new HashMap<>();
			if (resultVo.getServiceObject() != null) {
				map = putMessage(resultVo.getServiceObject());
				jsonObject.put("message", MessageType.MT007);
				jsonObject.put("code", 0);
			} else {
				jsonObject.put("message", "查无结果");
				jsonObject.put("code", 4);
			}
			jsonObject.put("data", map);
		} catch (Exception e) {
			e.printStackTrace();
			jsonObject.put("code", 5);
			jsonObject.put("message", MessageType.MT008);
		}

		return jsonObject;
	}

	/**
	 * 市民卡申请查询
	 * 
	 * @return
	 */
	public JSONObject smkApplication(Long userId) {
		// JSONArray jsonArray = new JSONArray();
		JSONObject jsonObject = new JSONObject();
		int code = 0;
		String message = "查询成功";
		String paperNo = "";
		String paperType = "";
		UserVO userVO = null;
		if (userId != null) {
			userVO = userMapper.selectByPrimaryKey(userId);
		} else {
			code = 1;
			message = "请正确登陆";
		}
		if (userVO != null && !StringUtil.isEmpty(userVO.getCustomerNo())) {
			paperNo = userVO.getPaperno();
			paperType = userVO.getPapertype();
		} else {
			code = 3;
			message = "新申请用户";
		}
		jsonObject.put("paperNo", paperNo);
		jsonObject.put("paperType", paperType);
		jsonObject.put("code", code);
		jsonObject.put("message", message);
		return jsonObject;
	}

	/**
	 * 12基础信息查询(卡相关信息查询)
	 * 
	 * @return
	 */
	public JSONObject queryPersonalCardInfoAndConsumeRecordsByPaperNo(String citizenCardNo, String year,
			String month, String transactionType,String appFlag) {
		// JSONArray jsonArray = new JSONArray();
		JSONObject jsonObject = new JSONObject();
		try {
			/*ResultVo rv = dockingInternetService.queryPersonalCardInfoAndConsumeRecordsByPaperNo(paperType, paperNo,
					cardPCode, startDate, endDate, year, month, transactionType);*/
			ResultVo rv = dockingInternetService.queryPersonalCardInfoAndConsumeRecordsByPaperNo(citizenCardNo,
					year, month, transactionType, appFlag);
			ResultStatus status = rv.getResultStatus();
			if (status.getCode() != 200) {
				if (StringUtil.isEmpty(status.getMessage())) {
					jsonObject.put("code", status.getCode());
					jsonObject.put("message", MessageType.MT008);
				} else {
					jsonObject.put("code", 4);
					jsonObject.put("message", status.getMessage());
				}
				return jsonObject;
			}
			ResultObject sObj = (ResultObject) rv.getServiceObject();

			List<Object> items = sObj.getItems();
			jsonObject.put("code", 0);
			jsonObject.put("data", items);
			jsonObject.put("message", MessageType.MT007);
		} catch (Exception e) {
			e.printStackTrace();
			jsonObject.put("code", 5);
			jsonObject.put("message", MessageType.MT008);
		}
		return jsonObject;
	}

	/**
	 * 13基础信息查询(卡申请进度查询)
	 */
	public JSONObject queryApplySchedule(String paperNo, String paperType, String cardPCode) {
		JSONObject jsonObject = new JSONObject();
		JSONArray jsonArray = new JSONArray();
		try {
			ResultVo resultVo = dockingInternetService.queryApplySchedule(paperNo, paperType, cardPCode);
			ResultStatus status = resultVo.getResultStatus();
			if (status.getCode() != 200) {
				jsonObject.put("code", status.getCode());
				if (StringUtil.isEmpty(status.getMessage())) {
					jsonObject.put("message", MessageType.MT006);
				} else {
					jsonObject.put("message", status.getMessage());
				}
				return jsonObject;
			}
			ResultObject ro = (ResultObject) resultVo.getServiceObject();
			List<Object> items = ro.getItems();
			for (Object obj : items) {
				Map map = putMessage(obj);
				map.put("date", map.get("date") != null ? map.get("date").toString().split("T")[0] : "");
				jsonArray.add(map);
			}
			jsonObject.put("code", 0);
			jsonObject.put("data", jsonArray);
			jsonObject.put("message", MessageType.MT007);
		} catch (Exception e) {
			e.printStackTrace();
			jsonObject.put("code", 5);
			jsonObject.put("message", MessageType.MT008);
		}
		return jsonObject;
	}

	/**
	 * 14 基础信息查询(通过挂失凭证号查询)
	 * 
	 * @param certNo
	 * @return
	 */
	public JSONObject queryPersonal(String certNo) {
		JSONObject jsonObject = new JSONObject();

		try {
			ResultVo resultVo = dockingInternetService.queryPersonalByCertNo(certNo);
			ResultStatus status = resultVo.getResultStatus();
			if (status.getCode() != 200) {
				jsonObject.put("code", status.getCode());
				if (StringUtil.isEmpty(status.getMessage())) {
					jsonObject.put("message", MessageType.MT006);
				} else {
					jsonObject.put("message", status.getMessage());
				}
				return jsonObject;
			}
			Map map = putMessage(resultVo.getServiceObject());
			jsonObject.put("code", 0);
			jsonObject.put("data", map);
			jsonObject.put("message", MessageType.MT007);
		} catch (Exception e) {
			e.printStackTrace();
			jsonObject.put("code", 5);
			jsonObject.put("message", MessageType.MT008);
		}

		return jsonObject;
	}

	/**
	 * 16基础信息查询(交易查询前,获取用户下所有卡产品)
	 * 
	 * @return
	 */
	public JSONObject queryCardProdunctByPersonal(String paperType, String paperNo, String cardPCode) {
		JSONObject jsonObject = new JSONObject();
		try {
			ResultVo resultVo = dockingInternetService.queryCardProdunctByPersonal(paperType, paperNo, cardPCode);
			if (resultVo.getResultStatus().getCode() != 200) {
				jsonObject.put("code", resultVo.getResultStatus().getCode());
				jsonObject.put("message", resultVo.getResultStatus().getMessage());
				return jsonObject;
			} else {
				ResultObject ro = (ResultObject) resultVo.getServiceObject();
				List<Object> items = ro.getItems();
				jsonObject.put("code", 0);
				jsonObject.put("data", items);
				jsonObject.put("message", MessageType.MT007);
			}
		} catch (Exception e) {
			e.printStackTrace();
			jsonObject.put("code", 5);
			jsonObject.put("message", MessageType.MT008);
		}

		return jsonObject;
	}

	/**
	 * 17查询信息
	 * 
	 * @return
	 */
	public JSONObject queryAllBranchStreet() {
		JSONObject jsonObject = new JSONObject();
		try {
			ResultVo vo = dockingInternetService.queryAllBranchStreet();
			// 核心接口校验
			if (vo.getResultStatus().getCode() != 200) {
				jsonObject.put("code", 1);
				jsonObject.put("message", vo.getResultStatus().getMessage());
				return jsonObject;
			}
			ResultObject obj = (ResultObject) vo.getServiceObject();
			List<Object> list = obj.getItems();
			if (list != null && list.size() > 0) {
				JSONArray jsonArray = new JSONArray();
				// 处理数据
				for (Object object : list) {
					jsonArray.add(putMessage((StreetNetVo) object));
				}
				jsonObject.put("code", 0);
				jsonObject.put("data", jsonArray);
			} else {
				jsonObject.put("code", 1);
				jsonObject.put("message", MessageType.MT_CX_7);
			}
		} catch (Exception e) {
			e.printStackTrace();
			jsonObject.put("code", 5);
			jsonObject.put("message", MessageType.MT008);
		}
		return jsonObject;
	}

	/**
	 * 18查询信息
	 * 
	 * @return
	 */
	public JSONObject queryOrgProperty() {
		JSONObject jsonObject = new JSONObject();
		try {
			ResultVo vo = dockingInternetService.queryOrgProperty();
			// 核心接口校验
			if (vo.getResultStatus().getCode() != 200) {
				jsonObject.put("code", 1);
				jsonObject.put("message", vo.getResultStatus().getMessage());
				return jsonObject;
			}
			ResultObject obj = (ResultObject) vo.getServiceObject();
			List<Object> list = obj.getItems();
			if (list != null && list.size() > 0) {
				JSONArray jsonArray = new JSONArray();
				// 处理数据
				for (Object object : list) {
					jsonArray.add(putMessage((StreetNetVo) object));
				}
				jsonObject.put("code", 0);
				jsonObject.put("data", jsonArray);
			} else {
				jsonObject.put("code", 1);
				jsonObject.put("message", MessageType.MT_CX_7);
			}
		} catch (Exception e) {
			e.printStackTrace();
			jsonObject.put("code", 5);
			jsonObject.put("message", MessageType.MT008);
		}
		return jsonObject;
	}

	/**
	 * 19查询网点详情
	 * 
	 * @return
	 */
	public JSONObject queryBranchByName(String branchName) {
		JSONObject jsonObject = new JSONObject();
		try {
			ResultVo vo = dockingInternetService.queryOrgByName(branchName);
			// 核心接口校验
			if (vo.getResultStatus().getCode() != 200) {
				jsonObject.put("code", 1);
				jsonObject.put("message", vo.getResultStatus().getMessage());
				return jsonObject;
			}
			BranchInternetVo obj = (BranchInternetVo) vo.getServiceObject();
			JSONArray jsonArray = new JSONArray();
			// 处理数据
			jsonArray.add(putMessage((BranchInternetVo) obj));
			jsonObject.put("code", 0);
			jsonObject.put("message", MessageType.MT007);
			jsonObject.put("data", jsonArray);
		} catch (Exception e) {
			jsonObject.put("code", 1);
			jsonObject.put("message", MessageType.MT008);
			e.printStackTrace();
		}
		return jsonObject;
	}

	/**
	 * 19查询网点详情
	 * 
	 * @return
	 */
	public JSONObject queryNation() {
		JSONObject jsonObject = new JSONObject();
		try {
			ResultVo resultVo = dockingInternetService.queryNation();

			JSONArray jsonArray = new JSONArray();
			// 处理数据
			jsonObject.put("code", 0);
			jsonObject.put("message", MessageType.MT007);
			jsonObject.put("data", resultVo);
		} catch (Exception e) {
			jsonObject.put("code", 1);
			jsonObject.put("message", MessageType.MT008);
			e.printStackTrace();
		}
		return jsonObject;
	}

	/**
	 * @param object
	 * @param map
	 * @return
	 */
	public Map putMessage(Object object) {
		Map map = new HashMap();
		try {
			Class clazz = object.getClass();
			Field[] fields = object.getClass().getDeclaredFields();// 获得属性
			for (Field field : fields) {
				PropertyDescriptor pd = new PropertyDescriptor(field.getName(), clazz);
				Method getMethod = pd.getReadMethod();// 获得get方法
				Object o = getMethod.invoke(object);// 执行get方法返回一个Object
				StringUtil.putIntoMap(map, pd.getName(), o);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return map;
	}

	

}
